package com.rd.student.ruanjian.class4.zhangrui.day8_2.AnimalTest1;

public class Store {

    public static Animal getInstance(String aniaml) {

        switch (aniaml) {
            case "dog":
                Dog dog = new Dog();
                return dog;
            case "pig":
                Pig pig = new Pig();
                return pig;
            default:
                Cat cat = new Cat();
                return cat;
        }
    }

    public static void main(String[] args) {
        Animal a1 = getInstance("dog");
        a1.voice();
        Animal a2 = getInstance("pig");
        a2.voice();
        Animal a3 = getInstance("000");
        a3.voice();
    }
}

